package com.yunxin.customui.controller;

import cn.hutool.core.lang.Console;
import com.alibaba.fastjson.JSON;
import com.yunxin.customui.bean.Action;
import com.yunxin.customui.bean.condition.button.SubmitButton;
import com.yunxin.customui.bean.condition.input.InputCondition;
import com.yunxin.customui.bean.condition.select.CascadeBean;
import com.yunxin.customui.bean.condition.select.NotCascade;
import com.yunxin.customui.service.createimpl.CustomCardImpl;
import com.yunxin.customui.service.dbservice.ConfigService;
import com.yunxin.tools.commonbean.WebResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

@RestController
@RequestMapping("customui")
public class TestController {
    @Autowired
    CustomCardImpl cardImpl;
    @Autowired
    ConfigService configService;

    /**
     * 测试
     */
    @RequestMapping("/conditionTest")
    public WebResultBean<Map<String, Object>> test(){
        Map<String, Object> stringObjectMap = testData();
        Console.log(JSON.toJSON(stringObjectMap));
        return new WebResultBean<>(stringObjectMap);
    }

    /**
     * 提交测试
     * 刷新单选下拉框
     */
    @RequestMapping("/submitTest")
    public WebResultBean<Map<String, Object>> submitTest(){
        NotCascade select = new NotCascade();
        select.addValues("内容4","4");
        select.addValues("内容5","5");
        select.addValues("内容6","6");
        select.setAttrName("testSelect");
        select.setType("select");
        Map<String, Object> result = new HashMap<>();
        result.put(Action.Refresh.buildKey("select"),select);
        return new WebResultBean<>(result);
    }

    /**
     * 测试 提交test2
     * 弹出框
     */
    @RequestMapping("/submitTest2")
    public WebResultBean<Map<String, Object>> submitTest2(){
        Map<String, Object> result = new HashMap<>();
        result.put(Action.Open.buildKey("open"),"http://www.baidu.com");
        return new WebResultBean<>(result);
    }

    /**
     * 测试数据
     */
    public static Map<String, Object> testData(){
        Map<String, Object> resultMap = new HashMap<>();

        SubmitButton button = new SubmitButton();
        button.setUrl("/customui/submitTest");
        button.setContext("测试提交");
        button.setType("submit");

        InputCondition input = new InputCondition();
        input.setAttrName("input");
        input.setPlaceholder("填写测试内容");
        input.setModuleLabel("测试input框");
        input.setType("input");

        NotCascade select = new NotCascade();
        select.addValues("内容1","1");
        select.addValues("内容2","2");
        select.addValues("内容3","3");
        select.setAttrName("testSelect");
        select.setType("select");




        CascadeBean selectCascade = new CascadeBean();
        LinkedList<CascadeBean.Cascade> list = new LinkedList<>();
        LinkedList<CascadeBean.Cascade> list2 = new LinkedList<>();
        list.add(new CascadeBean.Cascade("2级1","2.1"));
        list.add(new CascadeBean.Cascade("2级2","2.2"));
        list.add(new CascadeBean.Cascade("2级3","2.3"));
        list2.add(new CascadeBean.Cascade("2级4","2.4"));
        list2.add(new CascadeBean.Cascade("2级5","2.5"));
        list2.add(new CascadeBean.Cascade("2级6","2.6"));
        selectCascade.addValue(new CascadeBean.Cascade("1级1","1.1",list));
        selectCascade.addValue(new CascadeBean.Cascade("1级2","1.2",list2));
        selectCascade.setAttrName("cascade1&&cascade2");
        selectCascade.setDefaultValue("1.2&&2.5");
        selectCascade.setType("cascade");


        resultMap.put(Action.Refresh.buildKey("button"),button);
        resultMap.put(Action.Refresh.buildKey("input"),input);
        resultMap.put(Action.Refresh.buildKey("select"),select);
        resultMap.put(Action.Refresh.buildKey("selectCascade"),selectCascade);
        return resultMap;
    }

}
